package main.java.web.servlet;

import main.java.domain.Result;
import main.java.service.ResultService;
import main.java.service.impl.ResultServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/correctionDetailServlet")
public class CorrectionDetailServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String stu_id = request.getParameter("stu_id");
        String task_id = request.getParameter("task_id");

        HttpSession session = request.getSession();
        session.setAttribute("stu_id", stu_id);
        session.setAttribute("task_id", task_id);

        // 获取作业详情
        ResultService service = new ResultServiceImpl();
        Result result = service.find(Integer.parseInt(stu_id), Integer.parseInt(task_id));

        String path = result.getFilepath();
        String[] filenames = path.split(";");

        System.out.println(path);

        request.setAttribute("filenames", filenames);

        //
        request.getRequestDispatcher("/correction.jsp").forward(request, response);
    }
}
